package com.hailiao.beidou.message.data.location

import android.location.Location
import com.d10ng.common.coordinate.toLatitudeString
import com.d10ng.common.coordinate.toLongitudeString
import com.d10ng.datelib.curTime

/**
 * 位置信息
 * @Author d10ng
 * @Date 2023/11/17 16:44
 */
data class LocationInfo(
    // 定位时间戳，毫秒
    var timestamp: Long = 0L,
    // 纬度，-90.0 ~ +90.0
    var latitude: Double = 0.0,
    // 经度，-180.0 ~ +180.0
    var longitude: Double = 0.0,
    // 速度，千米/小时
    var speed: Float = 0f,
    // 方向，范围为[0,359]，0度为正北方向，顺时针
    var bearing: Float = 0f,
    // 海拔，米
    var altitude: Double = 0.0,
    // 定位精度，米
    var accuracy: Float = 0f,
    // 定位卫星数
    var satelliteCount: Int = 0
) {

    /**
     * 获取展示的位置信息
     * @return String
     */
    fun getPointShowString() =
        "${latitude.toLatitudeString("Fd°m′S.ss″")},${longitude.toLongitudeString("Fd°m′S.ss″")}"
}

fun Location.toLocationInfo() = LocationInfo().apply {
    this.timestamp = curTime
    this.latitude = this@toLocationInfo.latitude
    this.longitude = this@toLocationInfo.longitude
    this.speed = this@toLocationInfo.speed * 3.6f
    this.bearing = this@toLocationInfo.bearing
    this.altitude = this@toLocationInfo.altitude
    this.accuracy = this@toLocationInfo.accuracy
}
